package router

import (
	"XiangMu/middleware"
	"XiangMu/service"

	"github.com/gin-gonic/gin"
)

func Router() *gin.Engine {

	r := gin.Default()
	r.POST("/adminLogin/:sign", service.AdminLogin)
	r.POST("/userLogin", service.UserLogin)
	r.Use(middleware.LoginFilter())
	{
		user := r.Group("/stu").Use(middleware.AuthUserCheck())
		{
			user.GET("/stepInfo/:id", service.GetStepInfo)
			user.GET("/userInfo", service.SelectById)

			user.POST("/upload", service.Upload)
			user.POST("/logout", service.Logout)
			user.POST("/wordFill", service.UserWordFill)

			user.PUT("/stepInfo/:id", service.SaveStepInfo)
			user.PUT("/update", service.Update)
		}

		branch := r.Group("/branch").Use(middleware.AuthZhiBuCheck())
		{
			branch.DELETE("/userDel/:id", service.DeleteById)
			branch.DELETE("/userDelIds", service.DeleteByIds)

			branch.PUT("/stepInfo/:uid/:sid", service.SaveStepInfo)
			branch.PUT("/contacts/:uid", service.UpdateCTS)
			branch.PUT("/sponsor/:uid", service.UpdateSP)
			//branch.PUT("/branch/:uid", service.UpdateBranch)
			branch.PUT("/update/:id", service.UpdateById)
			branch.PUT("/next/:uid/:sid", service.StartNextStep)
			branch.PUT("/updateSelf", service.UpdateSelf)

			branch.POST("/addUsers", service.AddUserByExcel)
			branch.POST("/addUser", service.AddUser)
			branch.POST("/wordFill/:uid", service.GetUserWordFill)
			branch.POST("/excel", service.FillByExcel)

			branch.GET("/export", service.ExportUsersToExcel)
			branch.GET("/students", service.GetStuUsers)
			branch.GET("/stepInfo/:uid/:sid", service.AdminGetStepInfo)
			branch.GET("/status/:uid", service.GetUserStatus)
			branch.GET("/rawUsers", service.GetAllUsers)

		}
		committee := r.Group("/committee").Use(middleware.AuthDangWeiCheck())
		{
			committee.GET("/status/:uid", service.GetUserStatus)
			committee.GET("/stepInfo/:uid/:sid", service.AdminGetStepInfo)
			committee.GET("/branch/:bid", service.GetBranchById)
			committee.GET("/branches", service.GetBranches)
			committee.GET("/rawUsers", service.GetAllUsers)
			committee.GET("/students", service.GetStuUsers)
			committee.GET("/export", service.ExportUsersToExcel)

			committee.POST("/adduser", service.AddUser)
			committee.POST("/branch", service.AddBranch)
			committee.POST("/addUsers", service.AddUserByExcel)
			committee.POST("/wordFill/:uid", service.GetUserWordFill)

			committee.DELETE("/branchDel/:id", service.DelBByIds)

			committee.PUT("/stepInfo/:uid/:sid", service.SaveStepInfo)
			committee.PUT("/update/:id", service.UpdateById)
			committee.PUT("/contacts/:uid", service.UpdateCTS)
			committee.PUT("/sponsor/:uid", service.UpdateSP)
		}
	}
	return r
}
